﻿from math import pow, sqrt

g = 9.81

def pitagoras(x0, x1):
	return sqrt(pow(x0[0] - x1[0], 2) + pow(x0[1] - x1[1], 2))

def calculateSegmentTime(x0, x1, v0):
	if x0 == x1:
		return 0
	s = pitagoras(x0, x1)
	t = (g*(sqrt((2*g*s + v0 + v0*v0)/(g*g))) - v0)/g
	return t

def calculateVelocity(v0, t):
	return v0 + g*t
	

def calculateTime(points):
	sum = 0
	v0 = 0
	for i in range(0, len(points) - 1):
		t = calculateSegmentTime(points[i], points[i + 1], v0)
		v0 = calculateVelocity(v0, t)
		sum += t
	return sum